var jsonList = {};
jsonList.state=2;
var page = 1;
var rows = 10;
$(function (){
    //获取频道列表
    var jsonl = {};
    var result = JSON.stringify(jsonl);
    $.ajax({
        url: baseNews + "/api/data/channel/list?page=1&rows=200",
        type: "post",
        headers: { 'Content-Type': 'application/json' },
        dataType: "json",
        data: result,
        success: function (res) {
            console.log(res, 6666);
            if (res.code == 0) {
                var obj = $(".sh_pind");
                $(res.data.list).each(function (index, key) {
                    obj.append("<option value='" + key.id + "'>" + key.cname + "</option>");
                })
            }
        }
    })
    //获取专题id
    $.ajax({
        url: baseNews + "/api/data/article/special/select",
        success: function (res) {
            console.log(res);
            if (res.code == 0) {
                var obj = $(".zq_se");
                var obj1 = $(".atc_ztid");
                $(res.data).each(function (index, key) {
                    obj.append("<option value='" + key.id + "'>" + key.value + "</option>");
                    obj1.append("<option value='" + key.id + "'>" + key.value + "</option>");
                })
            }
        }
    })
    //获取频道列表
    // $.ajax({
    //     url: baseNews + "/api/data/special/channel/select",
    //     success: function (res) {
    //         console.log(res);
    //         if (res.code == 0) {
    //             var obj = $(".sh_pind");

    //             $(res.data).each(function (index, key) {
    //                 obj.append("<option value='" + key.id + "'>" + key.value + "</option>");               })
    //         }
    //     }
    // })
    //搜索
    $(".sh_pind").change(function () {
        jsonList.cid = $(this).val();
    })
    $(".sh_ss").click(function () {
        var arc_name = $(".zt_id").val();//专题id
        var arc_sele = $(".zt_mc").val();//文章名称
        var sh_ztzt = $(".sh_ztzt").val();//专题状态
        var sh_pind = $(".sh_pind").val();//专题频道
        console.log(arc_sele, 333)
        if (arc_name != "") {
            jsonList.sid  = arc_name
        }
        if (arc_sele !="") {
        } else {
            jsonList.stitle = arc_sele;
        }
        //var atc_ztid = $(".atc_ztid").val()//专题
        page = 1;
        getList();
    })

    //审核通过
    $(".sh_wzt").on("click",function (){
        var numCount = 0;
        var ids = '';
        $(".arc_isc").each(function (index, key) {
            if ($(this).prop("checked") == true) {
                numCount++;
                ids = ids + $(this).attr("oid") + ',';
            }
        })
        ids = ids.substring(0, ids.length - 1);
        //console.log(ids, 555);
        if (numCount >= 1) {
            //进行下一步
            var json = {}
            var result = JSON.stringify(json);
            zeroModal.confirm("确定要发布该短评吗？", function () {
                //置顶确认请求数据
                $.ajax({
                    url: baseNews + "/api/data/release/sr/ok?ids=" + ids,
                    type: "post",
                    headers: { 'Content-Type': 'application/json' },
                    dataType: "json",
                    data: result,
                    success: function (res) {
                        console.log(res,333)
                        if (res.code == 0) {
                            location.reload();
                        } else {
                            zeroModal.alert('发布短评失败');
                        }
                    }
                })
            })
        }else{
            zeroModal.alert('请选择至少一条短评进行发布');
        }
    })
    //取消审核
    $(".sh_wzqx").on("click", function () {
        var numCount = 0;
        var ids = '';
        $(".arc_isc").each(function (index, key) {
            if ($(this).prop("checked") == true) {
                numCount++;
                ids = ids + $(this).attr("oid") + ',';
            }
        })
        ids = ids.substring(0, ids.length - 1);
        //console.log(ids, 555);
        if (numCount >= 1) {
            //进行下一步
            var json = {}
            var result = JSON.stringify(json);
            zeroModal.confirm("确定要取消审核该短评吗？", function () {
                //置顶确认请求数据
                $.ajax({
                    url: baseNews + "/api/data/release/sr/ok?ids=" + ids,
                    type: "post",
                    headers: { 'Content-Type': 'application/json' },
                    dataType: "json",
                    data: result,
                    success: function (res) {
                        console.log(res, 333)
                        if (res.code == 0) {
                            location.reload();
                        } else {
                            zeroModal.alert('取消审核短评失败');
                        }
                    }
                })
            })
        } else {
            zeroModal.alert('请选择至少一条短评取消审核');
        }
    })
})
getList();
function getList() {
    var result = JSON.stringify(jsonList);
    $.ajax({
        url: baseNews + "/api/data/common/sr/list?page=" + page + "&rows=" + rows,
        type: "post",
        headers: { 'Content-Type': 'application/json' },
        dataType: "json",
        data: result,
        success: function (res) {
            console.log(result, 666);
            if (res.code == 0) {
                var result = res.data;
                var list = result.list;
                console.log(list, 9999)
                var html = "";
                $("#page").paging({
                    pageNo: page,
                    totalPage: result.totalpage,
                    totalSize: result.totals,
                    callback: function (num) {
                        page = num;
                        getList();
                    }
                })
                $(".arc_list").empty();
                $(list).each(function (index, key) {
                    var state = key.state;//文章的状态
                    var state1 = key.sstate//专题的状态
                    var newState = "";//文章的
                    var newState1 = "";//专题的
                    if (state == 1) {
                        newState = "待审核";
                    }
                    if (state == 2) {
                        newState = "待发布";
                    }
                    if (state == 3) {
                        newState = "已发布";
                    }
                    if (state == 10) {
                        newState = "有更新";
                    }
                    if (state == -1) {
                        newState = "审核失败";
                    }
                    if (state == -2) {
                        newState = "撤销发布";
                    }
                    //
                    if (state1 == 1) {
                        newState1 = "待审核";
                    }
                    if (state1 == 2) {
                        newState1 = "待发布";
                    }
                    if (state1 == 3) {
                        newState1 = "已发布";
                    }
                    if (state1 == 10) {
                        newState1 = "有更新";
                    }
                    if (state1 == -1) {
                        newState = "审核失败";
                    }
                    if (state1 == -2) {
                        newState1 = "撤销发布";
                    }
                    html += `<tr>
							<td>
								<input type="checkbox" oid="${key.id}" class="arc_isc" />
							</td>
							<td> ${key.id} </td>
							<td>${key.title}</td>
							<td>${newState}</td>
							<td>${key.sid}</td>
							<td>${key.stitle == null ? '' : key.stitle}</td>
							<td>${newState1}</td>
							<td>${key.cname == null ? '' : key.cname}</td>
							<td>${key.type}</td>
							<td>${key.top == true ? "是" : "否"}</td>
							<td>${key.recommend == true ? "是" : "否"}</td>
							<td>${key.diy == true ? "是" : "否"}</li>
							<td>${key.statement == true ? "有" : "无"}</td>
							<td style="display: none">${key.click}</td>
							<td style="display: none">${key.collect}</td>
							<td>${key.pass}</td>
							<td>${key.comment}</td>
							<td style="display: none">${key.hot}</td>
							<td>${key.username}</td>
							<td>${key.createtime}</td>
							<td>${key.updatetime}</td>
							<td>${key.atime}</td>
							<td>${key.rtime}</td>
							<td>${key.source}</td>
							<td>${key.author}</td>
							<td style="display: none">${key.stime}</td>
							<td>··</td>
						</tr>`;
                })
                $(".arc_list").append(html);
            }
        }

    })
    //分页

}